//
//  CustomHeaderViewController.m
//  ZFJFormKit
//
//  Created by 张福杰 on 2018/4/24.
//  Copyright © 2019 张福杰. All rights reserved.
//

#import "CustomHeaderViewController.h"
#import "MBProgressHUD+MBP.h"
#import "CustomHeaderView.h"

#import "ZFJFormKit.h"

@interface CustomHeaderViewController ()

@property (nonatomic,strong) ZFJFormTableView *tableView;
@property (nonatomic,strong) NSMutableArray<ZFJFormModel *> *dataArray;
@property (nonatomic,strong) ZFJFormCellConfig *configModel;

@end

@implementation CustomHeaderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setBaseBackButtonView];
    [self uiConfig];
    [self dataConfig];
}

- (void)uiConfig{
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"个人信息";
    
    [self.view addSubview:self.tableView];
    
    //CELL的通用配置Model，也可以根据不同的CELL分别配置
    ZFJFormCellConfig *configModel = [[ZFJFormCellConfig alloc] init];
    //左边title
    configModel.titleColor = [UIColor blackColor];
    configModel.titleFont = [UIFont fontWithName:@"PingFangSC-Regular" size:17];
    //左边ICON尺寸（如果有）
    configModel.iconSize = CGSizeMake(25, 25);
    //分割线的颜色
    configModel.separatorLineColor = [UIColor groupTableViewBackgroundColor];
    configModel.isHiddenLine = NO;
    //占位符颜色
    configModel.placeholderColor = [UIColor colorWithRed:0.776 green:0.776 blue:0.800 alpha:1.00];
    //控件左右两边的间距
    configModel.marginSize = 15;
    _configModel = configModel;
}

- (void)dataConfig{
    //姓名 不能修改，所以不能输入
    ZFJFormModel *name_model = [[ZFJFormModel alloc] init];
    name_model.formCellType = KFormCellLabelType;
    name_model.configModel = _configModel;
    name_model.title = @"姓名";
    name_model.value = @"张福杰";
    name_model.height = 50;
    [self.dataArray addObject:name_model];
    
    //昵称（单行输入 KFormCellTextFieldType）
    ZFJFormModel *nickName_model = [[ZFJFormModel alloc] init];
    nickName_model.formCellType = KFormCellTextFieldType;
    nickName_model.configModel = _configModel;
    nickName_model.title = @"昵称";
    nickName_model.placeholder = @"请输入您的昵称";
    nickName_model.height = 50;
    nickName_model.validateBlock = ^BOOL(ZFJFormModel * _Nullable model) {
        if(model.value <= 0){
            [MBProgressHUD SHOWPrompttext:model.placeholder];
            return NO;
        }
        return YES;
    };
    [self.dataArray addObject:nickName_model];
    
    self.tableView.dataArray = self.dataArray;
    
    CustomHeaderView *headerView = [[CustomHeaderView alloc] init];
    headerView.frame = CGRectMake(0, 0, ScreenWidth, (ScreenWidth * 394)/700);
    headerView.imageView.image = [UIImage imageNamed:@"topImage"];
    self.tableView.tableHeaderView = headerView;
    
    CustomHeaderView *footerView = [[CustomHeaderView alloc] init];
    footerView.frame = CGRectMake(0, 0, ScreenWidth, (ScreenWidth * 200)/700);
    footerView.imageView.image = [UIImage imageNamed:@"footerImg"];
    self.tableView.tableFooterView = footerView;
}

- (ZFJFormTableView *)tableView{
    if (_tableView == nil){
        ZFJFormConfig *formConfig = [[ZFJFormConfig alloc] init];
        formConfig.backgroundColor = [UIColor groupTableViewBackgroundColor];
        formConfig.heightFooter = 15.0;
        formConfig.footerViewBgColor = [UIColor groupTableViewBackgroundColor];
        
        _tableView = [[ZFJFormTableView alloc] initWithFrame:CGRectMake(0, KNavBarHei, ZFJForm_ScreenWidth, ZFJForm_ScreenHeight - KNavBarHei) config:formConfig];
        _tableView.didSelectRowBlock = ^(NSIndexPath * _Nullable indexPath, ZFJFormModel * _Nullable model) {
            NSLog(@"%@",model);
        };
    }
    return _tableView;
}

- (NSMutableArray<ZFJFormModel *> *)dataArray{
    if (_dataArray == nil){
        _dataArray = [[NSMutableArray alloc] init];
    }
    return _dataArray;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
